package edu.scau.mis.cloth.service.impl;

import edu.scau.mis.cloth.entity.GsUser;
import edu.scau.mis.cloth.dao.GsUserDao;
import edu.scau.mis.cloth.entity.Gs_user;
import edu.scau.mis.cloth.service.GsUserService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (GsUser)表服务实现类
 *
 * @author makejava
 * @since 2022-03-09 20:35:38
 */
@Service("gsUserService")
public class GsUserServiceImpl implements GsUserService {
    @Resource
    private GsUserDao gsUserDao;

    /**
     * 通过ID查询单条数据
     *
     * @param userId 主键
     * @return 实例对象
     */
    @Override
    public List<Map<String,Object>> queryById(Integer userId) {
        return this.gsUserDao.queryById(userId);
    }

    /**
     * 分页查询
     *
     * @param gsUser 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GsUser> queryByPage(GsUser gsUser, PageRequest pageRequest) {
        long total = this.gsUserDao.count(gsUser);
        return new PageImpl<>(this.gsUserDao.queryAllByLimit(gsUser, pageRequest), pageRequest, total);
    }

    public GsUser validate(String userName,Integer userPassword){
        return gsUserDao.validate(userName,userPassword);
    }

    /**
     * 新增数据
     *
     * @param gsUser 实例对象
     * @return 实例对象
     */
    @Override
    public Gs_user insert(Gs_user gsUser) {
        this.gsUserDao.insert(gsUser);
        return gsUser;
    }

    /**
     * 修改数据
     *
     * @param gsUser 实例对象
     * @return 实例对象
     */
    @Override
    public void update(Gs_user gsUser) {
         this.gsUserDao.update(gsUser);
    }
    public  List<Map<String,Object>> queryAll(){
       return this.gsUserDao.queryAll();
}
    /**
     * 通过主键删除数据
     *
     * @param userId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer userId) {
        return this.gsUserDao.deleteById(userId) > 0;
    }
}
